package logic

import (
	"context"
	"house/models/mysql"

	"house/bookingrpc/bookingrpc"
	"house/bookingrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookingAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookingAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookingAddLogic {
	return &BookingAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookingAddLogic) BookingAdd(in *bookingrpc.BookingAddRequest) (*bookingrpc.BookingAddResponse, error) {
	// todo: add your logic here and delete this line
	booking := mysql.BookIng{
		Address: in.Address,
		Types:   in.Types,
		Time:    in.Time,
		Contact: in.Contact,
		HouseId: int(in.HouseId),
		UserId:  int(in.UserId),
	}
	mysql.DB.Debug().Create(&booking)
	return &bookingrpc.BookingAddResponse{
		BookingId: int64(booking.ID),
	}, nil
}
